package com.lagou.edu.controller;

import com.lagou.edu.service.AuthCodeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/code")
public class CodeController {


    private final AuthCodeService authCodeService;

    public CodeController(AuthCodeService authCodeService) {
        this.authCodeService = authCodeService;
    }


    @GetMapping("/create/{email}")
    public boolean create(@PathVariable String email) {
        // ⽣成验证码并发送到对应邮箱，成功true，失败false
        return authCodeService.createAuth(email);
    }




    @GetMapping("/validate/{email}/{code}")
    public int validate(@PathVariable String email,
                        @PathVariable String code) {
        return authCodeService.validate(email, code);
    }




}
